package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.bizsys.domain.CustomerInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Service;
    import com.ruoyi.bizsys.mapper.CustReplenishInfoMapper;
import com.ruoyi.bizsys.domain.CustReplenishInfo;
import com.ruoyi.bizsys.service.ICustReplenishInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 客户补充信息记录Service业务层处理
 *
 * @author african-loan
 * @date 2022-03-31
 */
@Service
public class CustReplenishInfoServiceImpl extends ServiceImpl<CustReplenishInfoMapper,CustReplenishInfo> implements ICustReplenishInfoService {

    /**
     * 查询客户补充信息记录
     *
     * @param id 客户补充信息记录ID
     * @return 客户补充信息记录
     */
    @Override
    public CustReplenishInfo selectCustReplenishInfoById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询客户补充信息记录列表
     *
     * @param custReplenishInfo 客户补充信息记录
     * @return 客户补充信息记录
     */
    @Override
    public List<CustReplenishInfo> selectCustReplenishInfoList(CustReplenishInfo custReplenishInfo) {
        return this.list(new QueryWrapper<>(custReplenishInfo).last("order by id desc"));
    }

    /**
     * 新增客户补充信息记录
     *
     * @param custReplenishInfo 客户补充信息记录
     * @return 结果
     */
            @Override
    public int insertCustReplenishInfo(CustReplenishInfo custReplenishInfo) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                    custReplenishInfo.setCreateTime(DateUtils.getNowDate());
                                                                    return baseMapper.insert(custReplenishInfo);
    }

    /**
     * 修改客户补充信息记录
     *
     * @param custReplenishInfo 客户补充信息记录
     * @return 结果
     */
            @Override
    public int updateCustReplenishInfo(CustReplenishInfo custReplenishInfo) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            custReplenishInfo.setUpdateTime(DateUtils.getNowDate());
                            return baseMapper.updateById(custReplenishInfo);
    }

    /**
     * 批量删除客户补充信息记录
     *
     * @param ids 需要删除的客户补充信息记录ID
     * @return 结果
     */
            @Override
    public int deleteCustReplenishInfoByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除客户补充信息记录信息
     *
     * @param id 客户补充信息记录ID
     * @return 结果
     */
    @Override
    public int deleteCustReplenishInfoById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public CustReplenishInfo getOneByCustNo(String custNo) {
        QueryWrapper<CustReplenishInfo> queryWrapper = new QueryWrapper<CustReplenishInfo>().eq("cust_no", custNo).last("order by id desc limit 1");
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean updateStatus(String custNo, String state) {
        UpdateWrapper<CustReplenishInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("state",state);
        updateWrapper.eq("cust_no",custNo);
        return this.update(updateWrapper);
    }

}
